﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ERP_RORZE_DLL.Assembly
{
    public partial class intem_AssemblyCheck : UserControl
    {
        public int funcID;
        public bool showform;
        public int func_type;
        public string defaultvalue;
        public intem_AssemblyCheck()
        {
            InitializeComponent();
            this.funcID = 0;
            this.func_type = 0;
            this.showform = true;
            this.defaultvalue = null;
        }

        public void setLabel(string label)
        {
            this.itemLabel.Text = label + ":";
        }

        public void addValue(string value)
        {
            ComboboxItem item = new ComboboxItem();
            item.Value = value;
            item.Text = value;
            this.itemValue.Properties.Items.Add(item);
        }

        public void setValue(string value)
        {
            if (this.itemValue.Properties.Items.Count > 0)
            {
                for (int i = 0; i < this.itemValue.Properties.Items.Count; i++)
                {
                    ComboboxItem item = (ComboboxItem)this.itemValue.Properties.Items[i];
                    if (item.Value.ToString() == value)
                    {
                        this.itemValue.SelectedIndex = i;
                    }
                }
            }
            else
            {
                this.itemValue.Text = value;
            }
        }

        public void setDefaultValue(string value)
        {
            this.defaultvalue = value;
            this.itemValue.Text = this.defaultvalue;
        }
        public string getValue()
        {
            string ret = null;
            if ((this.func_type == 1) || (this.func_type == 3))
            {
                if (this.itemValue.SelectedIndex >= 0)
                {
                    ComboboxItem item = (ComboboxItem)this.itemValue.SelectedItem;
                    ret = item.Value.ToString();
                }
            }
            else
            {
                ret = this.itemValue.Text.Trim();
                if (string.IsNullOrEmpty(ret))
                {
                    ret = this.defaultvalue;
                }
            }            
            return ret;
        }

        public string getFuncName()
        {
            return this.itemLabel.Text;
        }

        public void resetValue()
        {
            if ((this.func_type == 1) || (this.func_type == 3))
            {
                this.itemValue.SelectedIndex = -1;                
            }
            else
            {
                this.itemValue.Text = this.defaultvalue;
            }
        }
    }
}
